package cn.jilian.trans.bizz.web;

import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import cn.jilian.common.domain.R;
import cn.jilian.common.dto.PageResult;
import cn.jilian.entity.Order;
import cn.jilian.trans.bizz.dto.TransPostOrder;
import cn.jilian.trans.bizz.service.OrderService;
import cn.jilian.trans.bizz.service.PostService;
import cn.jilian.trans.bizz.service.SupplierService;
import cn.jilian.trans.bizz.util.SessionUtil;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/driver")
public class DriverController {
	
	@Autowired
	private PostService postService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private SupplierService supplierService;
	
	@ApiOperation(value="查询指定订单的报价单明细")
	@GetMapping("/orderpost/{id}")
	public ModelAndView getOrderPostView(@PathVariable(name="id")Long id,HttpSession session) {
		ModelAndView mv=new ModelAndView("");
		
		return mv;
	}
	
	@ApiOperation(value="订单报价编辑界面")
	@GetMapping("/orderpost/edit/{orderId}")
	public ModelAndView getOrderPostEditView(Long orderId,HttpSession session) {
		Long transId=SessionUtil.getUnitId(session);
		
		ModelAndView mv=new ModelAndView("trans/post_fill");
		TransPostOrder post=postService.queryDetailedPost(orderId, transId);
		if(post!=null) {
			mv.addObject("postDetail", post);
		}
		return mv;
	}
	
	
	@ApiOperation(value="提交报价明细")
	@PostMapping("/orderpost/{orderId}")
	public ModelAndView submitOrderPost(@PathVariable(name="orderId")Long orderId,TransPostOrder post,HttpSession session) {
		ModelAndView mv=new ModelAndView("");
		Long unid=SessionUtil.getUnitId(session);
		Order order=orderService.queryOrderBySid(orderId);
		if(order==null) {
			
		}else {
			
		}
		Long supplierId=order.getFid();
		Set<Long> ids=supplierService.queryRelatedTransports(supplierId);
		if(!ids.contains(unid)) {
			
		}
		int rs=postService.save(post);
		
		return mv;
	}
	
	@ApiOperation(value="查询待报价的订单列表")
	@GetMapping("/orderlist")
	public PageResult<Map<String,Object>> getOrderList(HttpSession session){
		return null;
	}
	
	
	@ApiOperation(value="签订指定合同")
	@PostMapping("/contract/sign")
	public R signOrderContract(Long contractId,String hash) {
		return R.ok;
	}
	
	

}
